package com.ruoyi.project.cwsk.datestat.controller;

import com.ruoyi.common.utils.DateUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cwsk.datestat.domain.OverviewDto;
import com.ruoyi.project.cwsk.datestat.service.OverviewService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/cwsk/datastat/overview")
public class OverviewController extends BaseController {

    private String prefix = "cwsk/datastat";

    @Autowired
    private OverviewService overviewService;

    @RequiresPermissions("cwsk:overview:view")
    @GetMapping()
    public String channel()
    {
        return prefix + "/overview";
    }

    /**
     * 查询渠道商管理列表
     */
    @RequiresPermissions("cwsk:overview:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OverviewDto dto) {

        if(StringUtils.isEmpty(dto.getStartDate())){
            dto.setStartDate(DateUtils.dateTime(DateUtil.getLastTday()));
        }
        if(StringUtils.isEmpty(dto.getEndDate())){
            dto.setEndDate(DateUtils.getDate());
        }

        List<OverviewDto> list = overviewService.findOverview(dto);
        return getDataTable(list);
    }
}
